;(function(){
  'use strict';
  angular.module('controllers.userBehaviorAnalysis.srPerceptionUwrAnalysis')
  .controller('srPerceptionUwrAnalysisCtrl',srPerceptionUwrAnalysisCtrl);
  function srPerceptionUwrAnalysisCtrl($scope,srPerceptionUwrAnalysisSevice,CoreLoading,COREDATA,srPerceptionUwrAlSevice,CoreService){
  	$scope.flag = {
  		state: true,
  		arrow: false,
  		show: 'view'
  	};
  	//导出路径
  	$scope.formPrefix = COREDATA.FORMPREFIX+'analysisUserBehavior/apperceiveChurnRate/ChurnRateExport';
  	//页面查询项绑定对象
  	var date = new Date();
  	var year = date.getFullYear();
  	var month = date.getMonth();
  	$scope.params = {
  		startTime: new Date(year,month-6),
  		endTime: new Date(year,month-3)
  	};
  	var myEcharts = echarts.init(document.getElementById('doc'));
  	//查询
  	$scope.search = function(){
      if (!$scope.flag.state) {
        $scope.flag.state = true;
        return;
      }
			$scope.send = srPerceptionUwrAnalysisSevice.fmtSendData($scope.params);
			var timeTitle = srPerceptionUwrAnalysisSevice.fmtDateTitle($scope.send);
			//标题:时间+期间各业务线成功率感知用户流失率趋势;
			$scope.send.title = timeTitle + ' 各业务线成功率感知用户流失率趋势';
			CoreLoading.setState(true);
			srPerceptionUwrAnalysisSevice.churnRateQuery($scope.send,function(res){
				if(res.state === '10000' && res.data.length >= 1){
					myEcharts.clear();
					$scope.items = res.data;
					$scope.title = $scope.send.title;
					$scope.item = srPerceptionUwrAlSevice.getArrayData(res.data);
					var option = srPerceptionUwrAlSevice.getEchartsLineData($scope.item,res.data,$scope.title);
					//echarts图提示信息
					option.yAxis[0].axisLabel = { formatter: '{value} %' };
					myEcharts.setOption(option);
					$scope.outData = srPerceptionUwrAlSevice.exportView(myEcharts,$scope.send);
					$scope.flag.show = 'view';
          $scope.flag.arrow = false;
          $scope.flag.state = false;
				}else if(res.data.length === 0){
					$scope.flag.state = true;
					$scope.flag.arrow = true;
          $scope.flag.show = '';
					CoreService.dialog('查询无数据');
				}else {
					$scope.flag.state = true;
					$scope.flag.arrow = true;
          $scope.flag.show = '';
					CoreService.dialog('查询错误');
				}
				CoreLoading.setState(false);
			});

	};
		$scope.search();
	//监听表单,当表单有错时,禁止查询
	// $scope.$watch('myForm.$invalid', function(newValue) {
	// 	newValue ? $scope.btnDisabled = true : $scope.btnDisabled = false;
	// });
  }
  srPerceptionUwrAnalysisCtrl.$inject = ['$scope','srPerceptionUwrAnalysisSevice','CoreLoading','COREDATA','srPerceptionUwrAlSevice','CoreService'];
})();